#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@file:number_answer.py
@author:LifeTime
@date: 2018/05/08
@version:
    v1.0 2018-05-08 create
@input: 需要就写，不需要就不写
@output:需要就写，不需要就不写

你可以假设每个输入只对应一种答案，且同样的元素不能被重复利用。
示例:
    给定 nums = [2, 7, 11, 15], target = 9
    因为 nums[0] + nums[1] = 2 + 7 = 9
    所以返回 [0, 1]
"""

#20个测试通过19个 最后超时
def answer(nums,target):
    length=len(nums)
    for i in range(0,length):
        for j in range(i+1,length):
            if nums[i]+nums[j]==target:
                return [i ,j]

# 遇到排好序的list时递归 然提交时给定的数据未排序
# 递归测试
# def answer(nums,target):
#     nums.sort()
#     start=0
#     length=len(nums)-1
#     print(length)
#     mid =start+length//2
#     print(mid)
#     n=3
#     while n>0:
#         mid = start+length//2
#         print(start,mid,length)
#         print(nums[start]+nums[length])
#         if nums[start]+nums[length]==target:
#             print("==")
#             return [start,length]
#         elif nums[start]+nums[length]>=target:
#             print(">=")
#             length=mid-1
#         else:
#             print("<=")
#             start=mid+1
#         n-=1

nums=[2,7,11,15]
target=9
print(answer(nums,target))
